<template>
  <el-dialog
  class="PredictionInfoAdd"
    title="修改超前地质预报信息"
    :visible.sync="dialogEditorVisible"
    width="50%"
    :before-close="handleClose"
  >
    <el-form
      :inline="true"
      class="demo-form-inline"
      ref="form"
      :model="currentRow"
      label-width="120px"
    >
    <el-row>
        <el-col :span="12">
          <el-form-item
            label="预报开始里程"
            prop="startMileage"
            :rules="[
      { required: true, message: '请输入预报开始里程', trigger: 'blur' }
    ]"
          >
            <el-input v-model="currentRow.startMileage"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item
            label="预报结束里程"
            label-width="110px"
            prop="endMileage"
            :rules="[
      { required: true, message: '请输入预报结束里程', trigger: 'blur' }
    ]"
          >
            <el-input v-model="currentRow.endMileage"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="设计围岩级别" :rules="[
      { required: true, message: '请输入围岩级别', trigger: 'blur' }
    ]">
            <el-input v-model="currentRow.surroundGrade"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="预报级别" :rules="[
      { required: true, message: '请输入预报级别', trigger: 'blur' }
    ]">
            <el-input v-model="currentRow.predictionGrade"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="预报手段" :rules="[
      { required: true, message: '请选择预报手段', trigger: 'blur' }
    ]">
            <el-select style="width:100%" v-model="currentRow.predictionType" placeholder="请选择预报手段">
              <el-option label="TSP" value="TSP"></el-option>
              <el-option label="地质雷达" value="地质雷达"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="报告编号" :rules="[
      { required: true, message: '请输入报告编号', trigger: 'blur' }
    ]">
            <el-input v-model="currentRow.remarks"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="是否有不良地质体" :rules="[
      { required: true, message: '请选择是否有不良地质体', trigger: 'blur' }
    ]">
            <el-radio v-model="currentRow.result" @click.native="chooseIdClick(2)" label="1">是</el-radio>
            <el-radio v-model="currentRow.result" @click.native="chooseIdClick(1)" label="2">否</el-radio>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="预报结果" :rules="[
      { required: true, message: '请输入预报结果', trigger: 'blur' }
    ]">
            <el-input type="textarea" v-model="currentRow.predictionResult"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row v-if="showClass">
        <el-col :span="12">
          <el-form-item label="不良地质体描述">
            <el-input v-model="currentRow.geology"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="不良地质体长度">
            <el-input  v-model="currentRow.geologyLength"  placeholder="请输入米数"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="创建时间" :rules="[
      { required: true, message: '请输入创建时间', trigger: 'blur' }
    ]">
            <el-date-picker
              type="date"
              value-format="yyyy-MM-dd HH:mm:ss"
              placeholder="选择日期"
              v-model="currentRow.predictionTime"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="报告附件">
            <el-upload
              name="file"
              class="upload-demo"
              action="string"
              :http-request="beforeAvatarUploadThree"
              :on-preview="handlePreview"
              :on-remove="handleRemove"
              :before-remove="beforeRemove"
              multiple
              :limit="3"
              :on-success="handlesuccess"
              :on-error="handleerror"
              :on-exceed="handleExceed"
              :file-list="fileList"
            >
              <el-button size="small" type="primary">点击上传</el-button>
            </el-upload>
          </el-form-item>
        </el-col>
      </el-row>
  </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogEditorVisible = false">取 消</el-button>
      <el-button type="primary" @click="create">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import api from '../../../api'
import qs from 'qs'

export default {
  data() {
    return {
      showClass:false,
      wId:'',
      dialogEditorVisible: false,
      currentRow: {},
      fileList: [],
    }
  },
  props: {
    flag: {
      type: Boolean,
      default: false
    }
  },
  mounted() {
    this.$bus.$on('onShowPredictionEditor', (row) => {
      this.dialogEditorVisible = true
      this.currentRow = row.rowdata
      this.wId = row.wId
    })
  },
  methods: {
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then((_) => {
          done()
        })
        .catch((_) => {})
    },
    create() {
      api
        .advanceInfoupdate(qs.stringify(this.currentRow))
        .then((res) => {
          if (res.data.code == 2001) {
            this.$message({
              type: 'success',
              message: '更新成功!'
            })
            this.dialogEditorVisible = false
            this.$bus.$emit('onRefreshSection', this.scetion.wId)
          } else {
            this.$message({
              type: 'fail',
              message: '更新失败!'
            })
            this.dialogVisible = false
            this.$bus.$emit('onRefreshPrediction', this.wId)
          }
        })
        .catch((err) => {})
    },
    handlesuccess(response, file, fileList) {
      if (response.code == 2001) {
        this.form.resources = response.data
      }
    },
    beforeAvatarUploadThree(file) {
      let params = new FormData()
      params.append('file', file.file)
      api
        .AddrPlaneFileUpload(params)
        .then((res) => {
          if (res.data.code == 2001) {
            this.form.resources = res.data.data
          }
        })
        .catch((err) => {})
    },
    handleRemove(file, fileList) {
      console.log(file, fileList)
    },
    handlePreview(file) {
      console.log(file)
    },
    handleExceed(files, fileList) {
      this.$message.warning(
        `当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`
      )
    },
    beforeRemove(file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`)
    },
    handleerror(err, file, fileList) {
      console.log(err)
    },
    chooseIdClick(val){
      if (val == 1) {
        this.showClass = false
      } else {
        this.showClass = true
      }
    }
  }
}
</script>

<style scoped>
.avatar-uploader .el-upload {
  position: relative;
  overflow: hidden;
  cursor: pointer;
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
}
.avatar-uploader .el-upload:hover {
  border-color: #409eff;
}
.avatar-uploader-icon {
  width: 50px !important;
  height: 50px !important;
  font-size: 28px;
  line-height: 50px !important;
  color: #8c939d;
  text-align: center;
}
.avatar {
  display: block;
  width: 50px !important;
  height: 50px !important;
}
.imgbeforepad {
  padding-top: 0px !important;
}
.avatar-uploader .el-icon-plus {
  margin: 15px !important;
}
.PredictionInfoAdd :deep(.el-input--suffix .el-input__inner){
  width: 202px;
}
.PredictionInfoAdd :deep(.el-textarea__inner){
  width: 202px;
}
.PredictionInfoAdd :deep(.el-form--inline .el-form-item__content){
  width: 202px;
}
</style>